using System;
using System.Collections;
using System.Collections.Specialized;
using System.Data;
using System.Data.SqlTypes;
using System.Data.SqlClient;
using System.Text;
using ECommerce.DAL;


namespace Entity
{
	/// <summary>
	/// This object represents the Private Fields of temp_Order.
	/// </summary>
	
	[System.ComponentModel.DataObject]
    public class temp_Order : DatabaseUtility
    {
		#region temp_Order Private Fields


		Int32 _orderId;
		String _shippingFirstName = String.Empty;
		String _shippingLastName = String.Empty;
		String _shippingAddressLine1 = String.Empty;
		String _shippingAddressLine2 = String.Empty;
		String _shippingCity = String.Empty;
		String _shippingAddressState = String.Empty;
		String _shippingAddressCountry = String.Empty;
		String _shippingZipCode = String.Empty;
		String _shippingTelephoneNumber = String.Empty;
		String _shippingTelephoneNumber2 = String.Empty;
		String _shippingEmailAddress = String.Empty;
		String _shippingMethod = String.Empty;
		Decimal _shippingCost;
		String _shippingStatus = String.Empty;
		String _orderTrackNumber = String.Empty;
		Boolean _isResidential;
		String _gIftCardMessage = String.Empty;
		
		#endregion
		#region temp_Order Constractor
		/// <summary>
        /// Creates an empty object of temp_Order. 
        /// This is mainly used to create a new instance of temp_Order to add a new temp_Order.
        /// </summary>
		public temp_Order(){}
		
				
		/// <summary>
        /// Used to retrieve employee information from database, 
        /// which is also used by Update method to save information of an existing temp_Order.
        /// </summary>
		public temp_Order
		(
			Int32 orderId,
			String shippingFirstName,
			String shippingLastName,
			String shippingAddressLine1,
			String shippingAddressLine2,
			String shippingCity,
			String shippingAddressState,
			String shippingAddressCountry,
			String shippingZipCode,
			String shippingTelephoneNumber,
			String shippingTelephoneNumber2,
			String shippingEmailAddress,
			String shippingMethod,
			Decimal shippingCost,
			String shippingStatus,
			String orderTrackNumber,
			Boolean isResidential,
			String gIftCardMessage
		)
		{
			_orderId = orderId;	
			_shippingFirstName = shippingFirstName;	
			_shippingLastName = shippingLastName;	
			_shippingAddressLine1 = shippingAddressLine1;	
			_shippingAddressLine2 = shippingAddressLine2;	
			_shippingCity = shippingCity;	
			_shippingAddressState = shippingAddressState;	
			_shippingAddressCountry = shippingAddressCountry;	
			_shippingZipCode = shippingZipCode;	
			_shippingTelephoneNumber = shippingTelephoneNumber;	
			_shippingTelephoneNumber2 = shippingTelephoneNumber2;	
			_shippingEmailAddress = shippingEmailAddress;	
			_shippingMethod = shippingMethod;	
			_shippingCost = shippingCost;	
			_shippingStatus = shippingStatus;	
			_orderTrackNumber = orderTrackNumber;	
			_isResidential = isResidential;	
			_gIftCardMessage = gIftCardMessage;	
		}
		
		#endregion
		#region temp_Order Properties
		
		 /***********************************************************************************************
                                    -- PROPERTIES --        
         Contains all the properties representing the data fields of the current entity.
         ***********************************************************************************************/

        /// <summary>
        /// This is the Primary key value of the OrderId, which can't be assigned from the application,
        /// to ensure the data consistancy, by not letting the user to change the PK_temp_Order to update the data of an another temp_Order instance.
        /// For view or updation purpose, every temp_Order will be retrieved thru the proper 'Get' method.
        /// </summary>
		
		public Int32 OrderId
		{
			get {return _orderId;}	
		}
		
				
		public String ShippingFirstName
		{
			get {return _shippingFirstName;}
			set {_shippingFirstName = value;}
		}

		public String ShippingLastName
		{
			get {return _shippingLastName;}
			set {_shippingLastName = value;}
		}

		public String ShippingAddressLine1
		{
			get {return _shippingAddressLine1;}
			set {_shippingAddressLine1 = value;}
		}

		public String ShippingAddressLine2
		{
			get {return _shippingAddressLine2;}
			set {_shippingAddressLine2 = value;}
		}

		public String ShippingCity
		{
			get {return _shippingCity;}
			set {_shippingCity = value;}
		}

		public String ShippingAddressState
		{
			get {return _shippingAddressState;}
			set {_shippingAddressState = value;}
		}

		public String ShippingAddressCountry
		{
			get {return _shippingAddressCountry;}
			set {_shippingAddressCountry = value;}
		}

		public String ShippingZipCode
		{
			get {return _shippingZipCode;}
			set {_shippingZipCode = value;}
		}

		public String ShippingTelephoneNumber
		{
			get {return _shippingTelephoneNumber;}
			set {_shippingTelephoneNumber = value;}
		}

		public String ShippingTelephoneNumber2
		{
			get {return _shippingTelephoneNumber2;}
			set {_shippingTelephoneNumber2 = value;}
		}

		public String ShippingEmailAddress
		{
			get {return _shippingEmailAddress;}
			set {_shippingEmailAddress = value;}
		}

		public String ShippingMethod
		{
			get {return _shippingMethod;}
			set {_shippingMethod = value;}
		}

		public Decimal ShippingCost
		{
			get {return _shippingCost;}
			set {_shippingCost = value;}
		}

		public String ShippingStatus
		{
			get {return _shippingStatus;}
			set {_shippingStatus = value;}
		}

		public String OrderTrackNumber
		{
			get {return _orderTrackNumber;}
			set {_orderTrackNumber = value;}
		}

		public Boolean IsResidential
		{
			get {return _isResidential;}
			set {_isResidential = value;}
		}

		public String GIftCardMessage
		{
			get {return _gIftCardMessage;}
			set {_gIftCardMessage = value;}
		}
		

		#endregion
		#region temp_Order Static Methods
		/************************************************************************************
                                    -- CREATE METHOD (STATIC) --
        *************************************************************************************/
		/************************* Architecure note:**********************************
        Note 1:
        This method is specially useful for the case, where we need to use Object Data Source controls.
        For ObjectDataSource/SqlDataSource controls, the insert/update metnod requires paramters methods, rather property based methods.
        However, there is still a way to pass property based objects as method parameter for data source controls, 
        but in that case we could not use Sql type, as view controls or asp parameter control can only contain few of primitive type.
        The main reason to remain the Sql Type in our object architecture is it is faster and contains better way for null value support.
        
        Note 2: 
        Non-primary key: it should be primitive type, as the asp paramter control (included in data source control) supports only primitive types.
        /*****************************************************************************/
		[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Insert, true)]
        public static  Int32 CreateNewtemp_Order
		(
			String shippingFirstName,
			String shippingLastName,
			String shippingAddressLine1,
			String shippingAddressLine2,
			String shippingCity,
			String shippingAddressState,
			String shippingAddressCountry,
			String shippingZipCode,
			String shippingTelephoneNumber,
			String shippingTelephoneNumber2,
			String shippingEmailAddress,
			String shippingMethod,
			Decimal shippingCost,
			String shippingStatus,
			String orderTrackNumber,
			Boolean isResidential,
			String gIftCardMessage
		)
		{
			//creating an empty temp_Order object
            temp_Order temp_Order = new temp_Order();
				temp_Order.ShippingFirstName = shippingFirstName;
				temp_Order.ShippingLastName = shippingLastName;
				temp_Order.ShippingAddressLine1 = shippingAddressLine1;
				temp_Order.ShippingAddressLine2 = shippingAddressLine2;
				temp_Order.ShippingCity = shippingCity;
				temp_Order.ShippingAddressState = shippingAddressState;
				temp_Order.ShippingAddressCountry = shippingAddressCountry;
				temp_Order.ShippingZipCode = shippingZipCode;
				temp_Order.ShippingTelephoneNumber = shippingTelephoneNumber;
				temp_Order.ShippingTelephoneNumber2 = shippingTelephoneNumber2;
				temp_Order.ShippingEmailAddress = shippingEmailAddress;
				temp_Order.ShippingMethod = shippingMethod;
				temp_Order.ShippingCost = shippingCost;
				temp_Order.ShippingStatus = shippingStatus;
				temp_Order.OrderTrackNumber = orderTrackNumber;
				temp_Order.IsResidential = isResidential;
				temp_Order.GIftCardMessage = gIftCardMessage;
			
			return temp_Order.CreateNewtemp_Order(temp_Order);
		}
	
		/************************************************************************************
                 -- UPDATE METHODS (STATIC) --
        *************************************************************************************/

        /************************* Architecure note:**********************************
        Note 1:
        This method is specially useful for the case, where we need to use Object Data Source controls.
        For ObjectDataSource/SqlDataSource controls, the insert/update metnod requires paramters methods, rather property based methods.
        However, there is still a way to pass property based objects as method parameter for data source controls, 
        but in that case we could not use Sql type, as view controls or asp parameter control can only contain few of primitive type.
        The main reason to remain the Sql Type in our object architecture is it is faster and contains better way for null value support.
        
        Note 2: 
        There the two types of paramaters will be passed here.
         * a. Primary key paramater: it should be Sql type, as we will bind the primary key property for the view controls (form view, details view etc) as datakey.
         * b. Non-primary key: it should be primitive type, as the asp paramter control (included in data source control) supports only primitive types.
        /*****************************************************************************/
		
		[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update, true)]
        public static  bool Updatetemp_Order
		(
			Int32 orderId,
			String shippingFirstName,
			String shippingLastName,
			String shippingAddressLine1,
			String shippingAddressLine2,
			String shippingCity,
			String shippingAddressState,
			String shippingAddressCountry,
			String shippingZipCode,
			String shippingTelephoneNumber,
			String shippingTelephoneNumber2,
			String shippingEmailAddress,
			String shippingMethod,
			Decimal shippingCost,
			String shippingStatus,
			String orderTrackNumber,
			Boolean isResidential,
			String gIftCardMessage
		)
		{
			 temp_Order temp_Order =  temp_Order.Gettemp_OrderByOrderId(orderId);
			
				temp_Order.ShippingFirstName = shippingFirstName;
				temp_Order.ShippingLastName = shippingLastName;
				temp_Order.ShippingAddressLine1 = shippingAddressLine1;
				temp_Order.ShippingAddressLine2 = shippingAddressLine2;
				temp_Order.ShippingCity = shippingCity;
				temp_Order.ShippingAddressState = shippingAddressState;
				temp_Order.ShippingAddressCountry = shippingAddressCountry;
				temp_Order.ShippingZipCode = shippingZipCode;
				temp_Order.ShippingTelephoneNumber = shippingTelephoneNumber;
				temp_Order.ShippingTelephoneNumber2 = shippingTelephoneNumber2;
				temp_Order.ShippingEmailAddress = shippingEmailAddress;
				temp_Order.ShippingMethod = shippingMethod;
				temp_Order.ShippingCost = shippingCost;
				temp_Order.ShippingStatus = shippingStatus;
				temp_Order.OrderTrackNumber = orderTrackNumber;
				temp_Order.IsResidential = isResidential;
				temp_Order.GIftCardMessage = gIftCardMessage;
			
			return temp_Order.Updatetemp_Order(temp_Order);
		}

		/************************************************************************************
                         -- DELETE METHODS --
        *************************************************************************************/
        /************************* Architecure note:**********************************
        We have used the employeeId parameter as SqlInt32, to bind the delete method with object data source and view control directly.
        ****************************************************************************/
		[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update, true)]
        public static  bool Deletetemp_Order
		(
			Int32 orderId
		)
		{
			//Validate Input
			if(orderId <= GetOrderIdMinValue)
				throw (new ArgumentOutOfRangeException("orderId"));
				
			// Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
			AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
			AddParameterToSqlCmd(sqlCmd, "@OrderId",SqlDbType.Int, 0, ParameterDirection.Input, orderId);
			SetCommandType(sqlCmd,CommandType.StoredProcedure,SPR_TEMP_ORDER_DELETETEMP_ORDER);
			ExecuteScalarCmd(sqlCmd);
			int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
			return (returnValue == 0 ? false : true);
			
		}
		
		/// <summary>
        /// Deletes a set of employees from the database.
        /// </summary>
		public static bool Deletetemp_OrderList( System.Collections.Generic.List<Int32>  orderIdListToDelete)
		{
			//Validate Input
			foreach (Int32 orderId in orderIdListToDelete)
			    if(orderId <= GetOrderIdMinValue)
					throw (new ArgumentOutOfRangeException("orderId"));
			
			//performing deletion operation //

            string xmlString = FormatXMLForIdArray(orderIdListToDelete);
			
			// Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
			AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            AddParameterToSqlCmd(sqlCmd, "@OrderIdList", SqlDbType.Xml, xmlString.ToString().Length, ParameterDirection.Input, xmlString.ToString());
			SetCommandType(sqlCmd,CommandType.StoredProcedure,SPR_TEMP_ORDER_DELETETEMP_ORDERLIST);
			ExecuteScalarCmd(sqlCmd);
			int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
			return (returnValue == orderIdListToDelete.Count ? true : false);
		}
		
		/************************************************************************************
                                 -- GET BY PRIMARY METHODS --
        *************************************************************************************/
        /************************* Architecure note:**********************************
        Retrives an Employee from database, based on it's primary key.
        To view or update an employee, everytime we must have to use this type of 'get' method, 
        since we don't have direct access to the Primary key value for assigning value.
        We have used the employeeId parameter as SqlInt32, to bind the delete method with object data source and view control directly.
        /*****************************************************************************/
		[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
		public static temp_Order Gettemp_OrderByOrderId(Int32 orderId)
		{
			if(orderId <= GetOrderIdMinValue)
					throw (new ArgumentOutOfRangeException("orderId"));
				
		 	// Execute SQL Command
			SqlCommand sqlCmd = new SqlCommand();
			AddParameterToSqlCmd(sqlCmd, "@OrderId",SqlDbType.Int, 0, ParameterDirection.Input, orderId);
			SetCommandType(sqlCmd,CommandType.StoredProcedure,SPR_TEMP_ORDER_GETTEMP_ORDERBYORDERID);
			GenerateCollectionFromReader test = new GenerateCollectionFromReader(Generatetemp_OrderCollectionFromReader);
            CustomCollection<temp_Order> objCollection = ((CustomCollection<temp_Order>)ExecuteReaderCmd(sqlCmd, test));

            if (objCollection.Count > 0)
                return objCollection[0];
            else
                return null;
		}
		
		/************************************************************************************
                         -- GET BY FOREIGN KEY METHODS --
        *************************************************************************************/
		
		/************************************************************************************
                 -- GET ALL METHODS --
        *************************************************************************************/
		[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public static CustomCollection<temp_Order> GetAlltemp_Order()
		{
		
		 	// Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            SetCommandType(sqlCmd,CommandType.StoredProcedure,SPR_TEMP_ORDER_GETALLTEMP_ORDER);
            GenerateCollectionFromReader test = new GenerateCollectionFromReader(Generatetemp_OrderCollectionFromReader);
            CustomCollection<temp_Order> objCollection = ((CustomCollection<temp_Order>)ExecuteReaderCmd(sqlCmd, test));

            return objCollection;
		}
		
		[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public static CustomCollection<temp_Order> GetAlltemp_OrderPaged(String orderBy, Int32 startRowIndex, Int32 maximumRows)
        {
            //Validate Input
            if (orderBy == "")
                orderBy = "OrderId";

            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            AddParameterToSqlCmd(sqlCmd, "@orderby", SqlDbType.VarChar, 50, ParameterDirection.Input, orderBy);
            AddParameterToSqlCmd(sqlCmd, "@startrow", SqlDbType.Int, 0, ParameterDirection.Input, startRowIndex);
            AddParameterToSqlCmd(sqlCmd, "@pagesize", SqlDbType.Int, 0, ParameterDirection.Input, maximumRows);

            SetCommandType(sqlCmd,CommandType.StoredProcedure,SPR_TEMP_ORDER_GETALLTEMP_ORDERPAGED);

            GenerateCollectionFromReader test = new GenerateCollectionFromReader(Generatetemp_OrderCollectionFromReader);
            CustomCollection<temp_Order> objCollection = ((CustomCollection<temp_Order>)ExecuteReaderCmd(sqlCmd, test));
            return objCollection;
        }
		
		[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public static int GetAlltemp_OrderPagedCount(String orderBy, Int32 startRowIndex, Int32 maximumRows)
        {
            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();

            AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            SetCommandType(sqlCmd,CommandType.StoredProcedure,SPR_TEMP_ORDER_GETALLTEMP_ORDERPAGEDCOUNT);
            ExecuteScalarCmd(sqlCmd);

            int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
            return returnValue;
        }
		
		#endregion
		#region Employee Instance Methods
		/************************************************************************************
                                    -- SAVE (INSERT/UPDATE) METHODS (INSTANCE) --
        *************************************************************************************/
		/// <summary>
        /// Saves (inserts and updates) an Employee into database.
        /// The insertion occur if the EmployeeId conatins default value.
        /// Otherwises it updates the Employee into the database, based on the primary key value stored in EmployeeId.
        /// This technique ensures an Employee will not be updated without having a valid EmployeeId.
        /// </summary>
		public bool Save()
		{
			if(OrderId<= GetOrderIdMinValue)
			{
				Int32 TempId=CreateNewtemp_Order(this);
				if(TempId>0)
				{
					_orderId=TempId;
					return true;
				}
				else
				{
					// error occurs
					return false;
				}
			}
			else
			{	//This is a update Command
				return (Updatetemp_Order(this));
			}
			
		}
		
		public static Int32 CreateNewtemp_Order(temp_Order newtemp_Order)
		{
			// validate Parameters
			if (newtemp_Order == null)
				throw (new ArgumentNullException("newtemp_Order"));

			// Execute SQL Command
			SqlCommand sqlCmd = new SqlCommand();
			int length = 0;
			AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            
			AddParameterToSqlCmd(sqlCmd, "@ShippingFirstName",SqlDbType.NVarChar, 500, ParameterDirection.Input, newtemp_Order.ShippingFirstName);
			AddParameterToSqlCmd(sqlCmd, "@ShippingLastName",SqlDbType.NVarChar, 500, ParameterDirection.Input, newtemp_Order.ShippingLastName);
			AddParameterToSqlCmd(sqlCmd, "@ShippingAddressLine1",SqlDbType.NVarChar, 4000, ParameterDirection.Input, newtemp_Order.ShippingAddressLine1);
			AddParameterToSqlCmd(sqlCmd, "@ShippingAddressLine2",SqlDbType.NVarChar, 4000, ParameterDirection.Input, newtemp_Order.ShippingAddressLine2);
			AddParameterToSqlCmd(sqlCmd, "@ShippingCity",SqlDbType.NVarChar, 500, ParameterDirection.Input, newtemp_Order.ShippingCity);
			AddParameterToSqlCmd(sqlCmd, "@ShippingAddressState",SqlDbType.NVarChar, 500, ParameterDirection.Input, newtemp_Order.ShippingAddressState);
			AddParameterToSqlCmd(sqlCmd, "@ShippingAddressCountry",SqlDbType.NVarChar, 500, ParameterDirection.Input, newtemp_Order.ShippingAddressCountry);
			AddParameterToSqlCmd(sqlCmd, "@ShippingZipCode",SqlDbType.NVarChar, 50, ParameterDirection.Input, newtemp_Order.ShippingZipCode);
			AddParameterToSqlCmd(sqlCmd, "@ShippingTelephoneNumber",SqlDbType.NVarChar, 50, ParameterDirection.Input, newtemp_Order.ShippingTelephoneNumber);
			AddParameterToSqlCmd(sqlCmd, "@ShippingTelephoneNumber2",SqlDbType.NVarChar, 50, ParameterDirection.Input, newtemp_Order.ShippingTelephoneNumber2);
			AddParameterToSqlCmd(sqlCmd, "@ShippingEmailAddress",SqlDbType.NVarChar, 500, ParameterDirection.Input, newtemp_Order.ShippingEmailAddress);
			AddParameterToSqlCmd(sqlCmd, "@ShippingMethod",SqlDbType.NVarChar, 500, ParameterDirection.Input, newtemp_Order.ShippingMethod);
			AddParameterToSqlCmd(sqlCmd, "@ShippingCost",SqlDbType.Decimal, 9, ParameterDirection.Input, newtemp_Order.ShippingCost);
			AddParameterToSqlCmd(sqlCmd, "@ShippingStatus",SqlDbType.NVarChar, 500, ParameterDirection.Input, newtemp_Order.ShippingStatus);
			AddParameterToSqlCmd(sqlCmd, "@OrderTrackNumber",SqlDbType.NVarChar, 500, ParameterDirection.Input, newtemp_Order.OrderTrackNumber);
			AddParameterToSqlCmd(sqlCmd, "@IsResidential",SqlDbType.Bit, 0, ParameterDirection.Input, newtemp_Order.IsResidential);
			AddParameterToSqlCmd(sqlCmd, "@GIftCardMessage",SqlDbType.NVarChar, 500, ParameterDirection.Input, newtemp_Order.GIftCardMessage);
			
			SetCommandType(sqlCmd,CommandType.StoredProcedure,SPR_TEMP_ORDER_CREATENEWTEMP_ORDER);
			ExecuteScalarCmd(sqlCmd);
			return (Int32.Parse(sqlCmd.Parameters["@ReturnValue"].Value.ToString()));

		}
		/// <summary>
        /// Updates an temp_Order instance to the database.
        /// </summary>
		public static bool Updatetemp_Order(temp_Order newtemp_Order)
		{
			// validate Parameters
			if (newtemp_Order == null)
				throw (new ArgumentNullException("newtemp_Order"));

			// Execute SQL Command
			SqlCommand sqlCmd = new SqlCommand();
			int length = 0;
			AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            
			AddParameterToSqlCmd(sqlCmd, "@OrderId",SqlDbType.Int, 0, ParameterDirection.Input, newtemp_Order.OrderId);
			AddParameterToSqlCmd(sqlCmd, "@ShippingFirstName",SqlDbType.NVarChar, 500, ParameterDirection.Input, newtemp_Order.ShippingFirstName);
			AddParameterToSqlCmd(sqlCmd, "@ShippingLastName",SqlDbType.NVarChar, 500, ParameterDirection.Input, newtemp_Order.ShippingLastName);
			AddParameterToSqlCmd(sqlCmd, "@ShippingAddressLine1",SqlDbType.NVarChar, 4000, ParameterDirection.Input, newtemp_Order.ShippingAddressLine1);
			AddParameterToSqlCmd(sqlCmd, "@ShippingAddressLine2",SqlDbType.NVarChar, 4000, ParameterDirection.Input, newtemp_Order.ShippingAddressLine2);
			AddParameterToSqlCmd(sqlCmd, "@ShippingCity",SqlDbType.NVarChar, 500, ParameterDirection.Input, newtemp_Order.ShippingCity);
			AddParameterToSqlCmd(sqlCmd, "@ShippingAddressState",SqlDbType.NVarChar, 500, ParameterDirection.Input, newtemp_Order.ShippingAddressState);
			AddParameterToSqlCmd(sqlCmd, "@ShippingAddressCountry",SqlDbType.NVarChar, 500, ParameterDirection.Input, newtemp_Order.ShippingAddressCountry);
			AddParameterToSqlCmd(sqlCmd, "@ShippingZipCode",SqlDbType.NVarChar, 50, ParameterDirection.Input, newtemp_Order.ShippingZipCode);
			AddParameterToSqlCmd(sqlCmd, "@ShippingTelephoneNumber",SqlDbType.NVarChar, 50, ParameterDirection.Input, newtemp_Order.ShippingTelephoneNumber);
			AddParameterToSqlCmd(sqlCmd, "@ShippingTelephoneNumber2",SqlDbType.NVarChar, 50, ParameterDirection.Input, newtemp_Order.ShippingTelephoneNumber2);
			AddParameterToSqlCmd(sqlCmd, "@ShippingEmailAddress",SqlDbType.NVarChar, 500, ParameterDirection.Input, newtemp_Order.ShippingEmailAddress);
			AddParameterToSqlCmd(sqlCmd, "@ShippingMethod",SqlDbType.NVarChar, 500, ParameterDirection.Input, newtemp_Order.ShippingMethod);
			AddParameterToSqlCmd(sqlCmd, "@ShippingCost",SqlDbType.Decimal, 9, ParameterDirection.Input, newtemp_Order.ShippingCost);
			AddParameterToSqlCmd(sqlCmd, "@ShippingStatus",SqlDbType.NVarChar, 500, ParameterDirection.Input, newtemp_Order.ShippingStatus);
			AddParameterToSqlCmd(sqlCmd, "@OrderTrackNumber",SqlDbType.NVarChar, 500, ParameterDirection.Input, newtemp_Order.OrderTrackNumber);
			AddParameterToSqlCmd(sqlCmd, "@IsResidential",SqlDbType.Bit, 0, ParameterDirection.Input, newtemp_Order.IsResidential);
			AddParameterToSqlCmd(sqlCmd, "@GIftCardMessage",SqlDbType.NVarChar, 500, ParameterDirection.Input, newtemp_Order.GIftCardMessage);
			
			SetCommandType(sqlCmd,CommandType.StoredProcedure,SPR_TEMP_ORDER_UPDATETEMP_ORDER);
            ExecuteScalarCmd(sqlCmd);
			int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
			return (returnValue == 0 ? false : true);
		}
		#endregion
		
		#region temp_Order Related Collections
		/// <summary>
        /// Creates and returns a strongly typed collection of Employee custom entity. 
        /// The colelction is created through iterating on the IdataReader object which contains Employee information, as a set of records, similar to tabular format.
        /// </summary>
		public static CollectionBase  Generatetemp_OrderCollectionFromReader(IDataReader returnData) 
		{
			
			//creating the instance of Employee collection
			CustomCollection<temp_Order> coltemp_Order = new CustomCollection<temp_Order>();
			
			/************************* Architecure note:**********************************
             * Below code includes the null value functionality to retieve the data which has nill value in database end.
             * Design consideration:
             * Besides general data fields, special care should be taken for primary keys, to assign '0'/defaultvalue, rather passing 'Null' value in constructor parameter.
             * Although we are considering sqldb tyoe data for the current data container, but while retireving data from database end, through datareader object, we need to cast data reader objects using .net primitive data type, 
             * rather using sqldb type to cast, since data reader objects don't support sql db type to be casted.
             *****************************************************************************/

            //Iterating thriugh the data reader, to generate Employee collection.

			//getting the Employee collection by iterating thru the data reader
			while (returnData.Read()) 
			{
				//passing the temp_Order constructor parameters from the current instance of data reader fields.
				temp_Order newtemp_Order = new temp_Order
				(
					returnData["OrderId"]== System.DBNull.Value ? GetOrderIdMinValue : (Int32 ) returnData["OrderId"],
					returnData["ShippingFirstName"]== System.DBNull.Value ? string.Empty: (String ) returnData["ShippingFirstName"],
					returnData["ShippingLastName"]== System.DBNull.Value ? string.Empty: (String ) returnData["ShippingLastName"],
					returnData["ShippingAddressLine1"]== System.DBNull.Value ? string.Empty: (String ) returnData["ShippingAddressLine1"],
					returnData["ShippingAddressLine2"]== System.DBNull.Value ? string.Empty: (String ) returnData["ShippingAddressLine2"],
					returnData["ShippingCity"]== System.DBNull.Value ? string.Empty: (String ) returnData["ShippingCity"],
					returnData["ShippingAddressState"]== System.DBNull.Value ? string.Empty: (String ) returnData["ShippingAddressState"],
					returnData["ShippingAddressCountry"]== System.DBNull.Value ? string.Empty: (String ) returnData["ShippingAddressCountry"],
					returnData["ShippingZipCode"]== System.DBNull.Value ? string.Empty: (String ) returnData["ShippingZipCode"],
					returnData["ShippingTelephoneNumber"]== System.DBNull.Value ? string.Empty: (String ) returnData["ShippingTelephoneNumber"],
					returnData["ShippingTelephoneNumber2"]== System.DBNull.Value ? string.Empty: (String ) returnData["ShippingTelephoneNumber2"],
					returnData["ShippingEmailAddress"]== System.DBNull.Value ? string.Empty: (String ) returnData["ShippingEmailAddress"],
					returnData["ShippingMethod"]== System.DBNull.Value ? string.Empty: (String ) returnData["ShippingMethod"],
					returnData["ShippingCost"]== System.DBNull.Value ? 0: (Decimal ) returnData["ShippingCost"],
					returnData["ShippingStatus"]== System.DBNull.Value ? string.Empty: (String ) returnData["ShippingStatus"],
					returnData["OrderTrackNumber"]== System.DBNull.Value ? string.Empty: (String ) returnData["OrderTrackNumber"],
					returnData["IsResidential"]== System.DBNull.Value ? false: (Boolean ) returnData["IsResidential"],
					returnData["GIftCardMessage"]== System.DBNull.Value ? string.Empty: (String ) returnData["GIftCardMessage"]

				);
				//adding the Employee to the collection
				coltemp_Order.Add(newtemp_Order);
			}
			
			//returns the collection of Companys 
			return (coltemp_Order);
		}
		
		#endregion
		#region Constants and Default Values
		
		public static Int32 GetOrderIdMinValue
		{
			get
			{
				return 0;
			}
		}
		
		//create method related contants
			internal const string SPR_TEMP_ORDER_CREATENEWTEMP_ORDER="spr_temp_Order_CreateNewtemp_Order";
			internal const string SPR_TEMP_ORDER_UPDATETEMP_ORDER="spr_temp_Order_Updatetemp_Order";
			internal const string SPR_TEMP_ORDER_DELETETEMP_ORDER="spr_temp_Order_Deletetemp_Order";
			internal const string SPR_TEMP_ORDER_DELETETEMP_ORDERLIST="spr_temp_Order_Deletetemp_OrderList";
			internal const string SPR_TEMP_ORDER_GETTEMP_ORDERBYORDERID="spr_temp_Order_Gettemp_OrderByOrderId";
			internal const string SPR_TEMP_ORDER_GETALLTEMP_ORDER="spr_temp_Order_GetAlltemp_Order";
			internal const string SPR_TEMP_ORDER_GETALLTEMP_ORDERPAGED="spr_temp_Order_GetAlltemp_OrderPaged";
			internal const string SPR_TEMP_ORDER_GETALLTEMP_ORDERPAGEDCOUNT="spr_temp_Order_GetAlltemp_OrderPagedCount";
		
		#endregion
	}
}	
